package com.example.hotel;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hotel.R;

public class Games extends Activity implements OnClickListener {
	final Context context = this;
	Dialog show_message;
	TextView message;
	Integer a = 0;
	Integer b = 1;
	Integer c = 2;
	Integer tx1 = 0;
	Integer tx2 = 1;
	Integer tx3 = 2;
	int indext = 3;
	int i = 0;
	int i0 = 0;
	int i1 = 1;
	int i2 = 2;
	Integer item = 0;
	Integer item1 = 0;
	String[] menu = { "Angry Birds rio", "Bartender Mix", "cat war",
			"cut the rope", "Empire Vs Orcs", "Greedy Spider1",
			"Greedy Spider2", "Hangaroo", "Moron test", "Mystery Manor",
			"Spider", "Sudoku", "Touch The Frog", "Unlock Me", "Word Search",
			"Zombirds" };
	String[] it = { "com.rovio.angrybirdsrio",
			"com.netstar.bartendermixgenius", "com.westriversw.CatWar", "",
			"com.ezjoynetwork.empirevsorcs", "com.blyts.greedyspiders.free",
			"com.blyts.greedyspiders2.free", "com.wHangaroo2", "", "",
			"com.odesys.spider.ads", "com.icenta.sudoku.ui",
			"com.gamehourx.touchthefrog", "com.kiragames.unlockmefree",
			"com.xusheng.wordsearch", "pl.idreams.ShootTheZombirds" };
	String wellcome1 = "";
	Button bt_left, bt_right;
	
	TextView tv_txt1, tv_txt2, tv_txt3, tv_menu, wellcome;
	ImageView imv_img1, imv_img2, imv_img3, image_cart, backhome, image_msg,
			image_bill;
	Integer[] Image = { R.drawable.angry_birds_rio, R.drawable.bartender_mix,
			R.drawable.cat_war, R.drawable.cut_the_rope,
			R.drawable.empire_vs_orcs, R.drawable.greedy_spider1,
			R.drawable.greedy_spider2, R.drawable.hangaroo,
			R.drawable.moron_test, R.drawable.mystery_manor, R.drawable.spider,
			R.drawable.sudoku, R.drawable.touch_the_frog,
			R.drawable.unblock_me, R.drawable.word_search, R.drawable.zombirds };
	String lang = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hotel_info);
		String strmenu;
		lang = ((Global) getApplicationContext()).lang;
		wellcome = (TextView) findViewById(R.id.tvWellcome);
		bt_left = (Button) findViewById(R.id.left);
		bt_right = (Button) findViewById(R.id.right);
		imv_img1 = (ImageView) findViewById(R.id.image1);
		imv_img2 = (ImageView) findViewById(R.id.image2);
		imv_img3 = (ImageView) findViewById(R.id.image3);
		backhome = (ImageView) findViewById(R.id.imagehome);
		image_cart = (ImageView) findViewById(R.id.image_cart);
		image_msg = (ImageView) findViewById(R.id.image_msg);
		image_bill = (ImageView) findViewById(R.id.image_bill);
		tv_txt1 = (TextView) findViewById(R.id.tv1);
		tv_txt2 = (TextView) findViewById(R.id.tv2);
		tv_txt3 = (TextView) findViewById(R.id.tv3);
		tv_menu = (TextView) findViewById(R.id.tvMenu);
		bt_left.setOnClickListener(this);
		bt_right.setOnClickListener(this);
		imv_img1.setOnClickListener(this);
		imv_img2.setOnClickListener(this);
		imv_img3.setOnClickListener(this);
		image_cart.setOnClickListener(this);
		backhome.setOnClickListener(this);
		image_msg.setOnClickListener(this);
		image_bill.setOnClickListener(this);
		item = Image.length % 3;
		item1 = Image.length - item;
		imv_img1.setImageResource(Image[a]);
		imv_img2.setImageResource(Image[b]);
		imv_img3.setImageResource(Image[c]);
		tv_txt1.setText(menu[i0]);
		tv_txt2.setText(menu[i1]);
		tv_txt3.setText(menu[i2]);
		TextView tvAmount = (TextView)findViewById(R.id.tvAmount);
		tvAmount.setText("("+((Global)getApplicationContext()).cart_count.toString()+")");
		wellcome.setText(((Global) getApplicationContext()).wellcome);
		if (lang.equals("th")) {
			strmenu = "เน€เธเธก";
		} else {
			strmenu = "Game";
		}
		tv_menu.setText(strmenu);

		/*------setfonts------*/
		Typeface Font = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-Kittithada.ttf");
		Typeface FontBold = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-KittithadaBold.ttf");
		TextView tv_amount = (TextView) findViewById(R.id.tvAmount);
		tv_txt1.setTypeface(Font);
		tv_txt2.setTypeface(Font);
		tv_txt3.setTypeface(Font);
		tv_amount.setTypeface(Font);
		wellcome.setTypeface(FontBold);
		tv_menu.setTypeface(FontBold);
		/*--------------------*/

	}

	public void onClick(View v) {
		PackageManager manager = getPackageManager();
		Intent is = new Intent(Intent.ACTION_MAIN);
		String it_name;
		switch (v.getId()) {
		case R.id.right:

			if (item == 1 && i + 3 == item1) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;
				imv_img1.setImageResource(Image[i0]);
				imv_img2.setImageResource(0);
				imv_img2.setEnabled(false);
				imv_img3.setImageResource(0);
				imv_img3.setEnabled(false);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText("");
				tv_txt3.setText("");

			} else if (item == 2 && i + 3 == item1) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;

				imv_img1.setImageResource(Image[i0]);
				imv_img2.setImageResource(Image[i1]);
				imv_img3.setImageResource(0);
				imv_img3.setEnabled(false);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText("");

			} else if (i2 + 3 < Image.length) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;

				indext++;
				a = Image[i0];
				b = Image[i1];
				c = Image[i2];
				imv_img1.setImageResource(a);
				imv_img2.setImageResource(b);
				imv_img3.setImageResource(c);
				imv_img1.setEnabled(true);
				imv_img2.setEnabled(true);
				imv_img3.setEnabled(true);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText(menu[i2]);
			}

			break;
		case R.id.left:

			if (i > 0 && i0 < Image.length) {
				i -= 3;
				i0 -= 3;
				i1 -= 3;
				i2 -= 3;

				c = Image[i2];
				b = Image[i1];
				a = Image[i0];
				imv_img1.setImageResource(a);
				imv_img2.setImageResource(b);
				imv_img3.setImageResource(c);
				imv_img1.setEnabled(true);
				imv_img2.setEnabled(true);
				imv_img3.setEnabled(true);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText(menu[i2]);
			}
			break;
		case R.id.image1:
			try {
				it_name = it[i0];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
				break;
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i0],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.image2:
			try {
				it_name = it[i1];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
				break;
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i1],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.image3:
			try {
				it_name = it[i2];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
				break;
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i2],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.imagehome:
			startActivity(new Intent(Games.this, home.class));
			wellcome.setText(((Global) getApplicationContext()).wellcome);
			break;
		case R.id.image_cart:
			((Global) getApplicationContext()).nameCart = "show_cart";
			//((Global) getApplicationContext()).callpage = "Games";
			startActivity(new Intent(Games.this, Add_cart.class));
			break;
		case R.id.image_msg:
			//((Global) getApplicationContext()).callpage = "Games";
			startActivity(new Intent(Games.this, Message_list.class));
			break;
		case R.id.image_bill:
			((Global) getApplicationContext()).callpage = "Games";
			startActivity(new Intent(Games.this, Billing_history.class));
			break;
		}
	}
}
